This page is about trend in personal consumption in the US
TODO:
Change colors;
Add description.
consumption_product = readxl::read_excel("data/consumption_product.xlsx") %>%
janitor::clean_names() %>%
pivot_longer(
x2019_q1 : x2021_q3,
names_to = "time",
names_prefix = "x",
values_to = "consumption"
)
consumption_function = readxl::read_excel("./data/consumption_function.xlsx") %>%
janitor::clean_names() %>%
filter(as.numeric(line) <= 28) %>%
pivot_longer(
x2019_q1 : x2021_q3,
names_to = "time",
names_prefix = "x",
values_to = "consumption"
) %>%
mutate(functions = recode(functions, `Household consumption expenditures (for services)` = "household",
`Final consumption expenditures of nonprofit institutions serving households (NPISHs)1` = "nonprofit consumption"))
general_1 = consumption_function %>%
filter(functions %in% c("Goods","Services"))
covid_seasonal = read_csv("covid_seasonal.csv") %>%
rename(time = date) %>%
select(time, quarterly)
consumption_seasonal = general_1 %>%
select(-line)
covid_consumption = left_join(consumption_seasonal, covid_seasonal, by = "time")
joint_plot = plot_ly(covid_consumption, x = ~time) %>%
add_trace(y = ~consumption, type = "scatter", mode = "lines", color = ~functions, yaixs = "y") %>%
add_trace(y = ~quarterly, type = "bar", name = "Covid Cases", yaxis = "y2") %>%
layout(title = "Consumption of Goods and Services Compared with Covid Cases",
yaxis=list(title = "consumption expenditure", side="left"),
yaxis2=list(title = "covid cases", side="right",overlaying="y"),
showlegend=TRUE)
joint_plot
general_2 = consumption_function %>%
filter(functions %in% c("Durable goods","Nondurable goods","household","nonprofit consumption")) %>%
select(-line) %>%
pivot_wider(names_from = functions, values_from = consumption) %>%
janitor::clean_names()
subfig_1 = plot_ly(general_2, x = ~time, y = ~durable_goods, type = "bar", name = "Durable Goods") %>%
add_trace(y = ~nondurable_goods, name = "Nondurable Goods") %>%
layout(title = "Decomposition of Consumption of Goods",
yaxis = list(title = "Consumption"), barmode = "stack",
legend = list(orientation = 'h', x = 0, y = -0.2))
subfig_1
durable_goods =
consumption_function %>%
filter(functions %in% c("Motor vehicles and parts","Furnishings and durable household equipment","Recreational goods and vehicles","Other durable goods"))
durable_goods %>%
plot_ly(x = ~time, y = ~consumption, type = 'scatter', mode = 'lines', yaxis="y", color = ~functions) %>%
layout(title = "Decomposition of Consumption in Durable Goods",
legend = list(orientation = 'h', x = 0, y = -0.2))
nondurable_goods =
consumption_function %>%
filter(functions %in% c("Food and beverages purchased for off-premises consumption","Clothing and footwear","Gasoline and other energy goods","Other nondurable goods"))
nondurable_goods %>%
plot_ly(x = ~time, y = ~consumption, type = 'scatter', mode = 'lines', yaxis="y", color = ~functions) %>%
layout(title = "Decompostion of Consumption in Nondurable Goods",
legend = list(orientation = 'h', x = 0, y = -0.2))
subfig_2 = plot_ly(general_2, x = ~time, y = ~household, type = "bar", name = "Household", colors = "Dark2") %>%
add_trace(y = ~nonprofit_consumption, name = "Nonprofit Consumption", colors = "Dark2") %>%
layout(title = "Decomposition of Consumption in Services ",
yaixs = list(title = "Consumption"), barmode = "stack",
legend = list(orientation = 'h', x = 0, y = -0.2))
subfig_2
household_consumption =
consumption_function %>%
filter(functions %in% c("Housing and utilities","Health care","Transportation services","Recreation services","Food services and accommodations","Financial services and insurance","Other services"))
household_consumption %>%
plot_ly(x = ~time, y = ~consumption, type = 'scatter', mode = 'lines', yaxis="y", color = ~functions) %>%
layout(title = "Decomposition of Consumption in Household Services",
legend = list(orientation = 'h', x = 0, y = -0.2))
durable_goods_radar = durable_goods %>%
filter(time %in% c("2019_q1", "2021_q3")) %>%
select(functions, time, consumption) %>%
pivot_wider(names_from = functions, values_from = consumption)
total = rep(1,5)
start = rep(0,5)
durable_goods_radar = rbind(total, start, durable_goods_radar)[,-1]
rownames(durable_goods_radar) = c("1", "2", "2019_q1", "2021_q3")
colnames(durable_goods_radar) = c("motor", "furnishing", "recreation", "other")
durable_goods_radar[3,] = durable_goods_radar[3,]/1473292
durable_goods_radar[4,] = durable_goods_radar[4,]/1984391
durable_goods_radar[-c(1,2),] %>%
knitr::kable()
| motor | furnishing | recreation | other |
|---|---|---|---|
| 0.3394256 | 0.2387931 | 0.2761163 | 0.1456649 |
| 0.3303764 | 0.2366091 | 0.2889768 | 0.1440371 |
radar_1 = radarchart(durable_goods_radar)
nondurable_goods_radar = nondurable_goods %>%
filter(time %in% c("2019_q1", "2021_q3")) %>%
select(functions, time, consumption) %>%
pivot_wider(names_from = functions, values_from = consumption)
nondurable_goods_radar = rbind(total, start, nondurable_goods_radar)[,-1]
rownames(nondurable_goods_radar) = c("1", "2", "2019_q1", "2021_q3")
colnames(nondurable_goods_radar) = c("food/beverage", "clothing", "energy", "other")
nondurable_goods_radar[3,] = nondurable_goods_radar[3,]/2909515
nondurable_goods_radar[4,] = nondurable_goods_radar[4,]/3509766
nondurable_goods_radar[-c(1,2),] %>%
knitr::kable()
| food/beverage | clothing | energy | other |
|---|---|---|---|
| 0.3483196 | 0.1351971 | 0.1113089 | 0.4051741 |
| 0.3551200 | 0.1367587 | 0.1078300 | 0.4002914 |
radar_2 = radarchart(nondurable_goods_radar)
household_consumption_radar = household_consumption %>%
filter(time %in% c("2019_q1", "2021_q3")) %>%
select(functions, time, consumption) %>%
pivot_wider(names_from = functions, values_from = consumption)
total = rep(1,8)
start = rep(0,8)
household_consumption_radar = rbind(total, start, household_consumption_radar)[,-1]
rownames(household_consumption_radar) = c("1", "2", "2019_q1", "2021_q3")
colnames(household_consumption_radar) = c("housing", "healthcare", "transports", "recreation", "accomodation", "finance", "other")
household_consumption_radar[3,] = household_consumption_radar[3,]/9336650
household_consumption_radar[4,] = household_consumption_radar[4,]/9984527
household_consumption_radar[-c(1,2),] %>%
knitr::kable()
| housing | healthcare | transports | recreation | accomodation | finance | other |
|---|---|---|---|---|---|---|
| 0.2714813 | 0.2579861 | 0.0513708 | 0.0614477 | 0.1057028 | 0.1238437 | 0.1281675 |
| 0.2793373 | 0.2583677 | 0.0461719 | 0.0516284 | 0.1083851 | 0.1279287 | 0.1281807 |
radar_3 = radarchart(household_consumption_radar)